﻿@model IEnumerable<GolfLeague.EditModels.ScoreCardEditModel>

@if (Model.Count() == 0)
{
    <h4>No scorecards exist for this round.</h4>
}
else
{
    foreach (var scoreCard in Model)
    {
        <table cellpadding="0" cellspacing="0">
            <tr>
                <th>Holes</th>
        @foreach (var item in scoreCard.FrontHoles)
        {
                <th style="text-align:center">
                    @item.HoleNumber
                </th>
        }
                <th>Total</th>
                <th>Hdc</th>
                <th>Net</th>
            </tr>
            <tr id="row-FrontTeeBox-@scoreCard.FrontHoleDetails.TeeBox.TeeBoxID" style="background-color:@scoreCard.FrontHoleDetails.TeeBox.TeeBoxName" @if (String.Compare(scoreCard.FrontHoleDetails.TeeBox.TeeBoxName, "White", true) != 0)
                                                    {@Html.Raw("style=\"color:White\"")} >
                <td style="white-space:nowrap;">
                    @scoreCard.FrontHoleDetails.TeeBox.TeeBoxName (@scoreCard.FrontHoleDetails.TeeBox.Rating/@scoreCard.FrontHoleDetails.TeeBox.Slope)
                </td>
        @foreach (var holeInfo in scoreCard.FrontHoleDetails.HoleDetail)
        {
                <td align="center">
                    @holeInfo.Yardage
                </td>
        }
                <td>@scoreCard.FrontHoleDetails.HoleDetail.Sum(y => y.Yardage)</td>
                <td></td>
                <td></td>
            </tr>
            <tr id="row-FrontPar-@scoreCard.FrontHoleDetails.TeeBox.TeeBoxID" @if (String.Compare(scoreCard.FrontHoleDetails.TeeBox.TeeBoxName, "White", true) != 0)
                                              {@Html.Raw("style=\"color:" + @scoreCard.FrontHoleDetails.TeeBox.TeeBoxName + "\"")} >
                <td>
                    Par
                </td>
        @foreach (var holeInfo in scoreCard.FrontHoleDetails.HoleDetail)
        {
                <td align="center">
                    @holeInfo.Par
                </td>
        }
                <td>@scoreCard.FrontHoleDetails.HoleDetail.Sum(p => p.Par)</td>
                <td></td>
                <td></td>
            </tr>
            <tr>
                <td>Handicap</td>
        @foreach (var item in scoreCard.FrontHoles)
        {
                <td align="center">
                    @item.Handicap
                </td>
        }
                <td></td>
                <td></td>
                <td></td>
            </tr>
        @foreach (var match in scoreCard.PlayerMatches) {
            <tr>
                <td>@match.PlayerMatch.Player.FirstName.Substring(0, 1). @match.PlayerMatch.Player.LastName</td>
                <!--if (match.PlayerMatch.Player.PlayerHandicaps.Where(p => p.PlayerID == match.PlayerMatch.PlayerID).OrderBy(h => h.CreatedOn).Last().Handicap > (match.PlayerMatch.Player.PlayerHandicaps.Where(p => p.PlayerID == match.PlayerMatch.OpponentID).OrderBy(h => h.CreatedOn).Last().Handicap) && !(match.PlayerMatch.Player.Sub))-->
                @if (match.PlayerAHandicap > match.PlayerBHandicap && !(match.PlayerMatch.Player.Sub))
                {
                    for (int i = 0; i < 9; i++) {
                        <td class=@if (match.HandicapStrokes[i].Strokes == 1) {
                            @: "handicap Strokes1"
                        } else if (match.HandicapStrokes[i].Strokes == 2) {
                            @: "handicap Strokes2"
                        } else if (match.HandicapStrokes[i].Strokes == 3) {
                            @: "handicap Strokes3"
                        } else {
                            @: "handicap"
                        }>
                        </td>
                    }
                }
                else
                {
                    for (int i = 0; i < 9; i++)
                    {
                        <td class="handicap"></td>
                    }
                }
                <td></td>
                <td align="center">@match.PlayerAHandicap</td>
                <td></td>
            </tr>
            <tr>
                <td>@match.OpponentMatch.Player.FirstName.Substring(0, 1). @match.OpponentMatch.Player.LastName</td>
                <!--if (match.IndividualMatch.Player2.Handicap > match.IndividualMatch.Player1.Handicap && !(match.IndividualMatch.Player1.Sub))-->
                @if (match.PlayerBHandicap > match.PlayerAHandicap && !(match.OpponentMatch.Player.Sub))
                {
                    for (int i = 0; i < 9; i++) {
                        <td class=@if(match.HandicapStrokes[i].Strokes == 1) {
                            @: "handicap Strokes1"
                        } else if(match.HandicapStrokes[i].Strokes == 2) {
                            @: "handicap Strokes2"
                        } else if(match.HandicapStrokes[i].Strokes == 3) {
                            @: "handicap Strokes3"
                        } else {
                            @: "handicap"
                        }>
                        </td>
                    }
                }
                else
                {
                    for (int i = 0; i < 9; i++)
                    {
                        <td class="handicap"></td>
                    }
                }
                <td></td>
                <td align="center">@match.PlayerBHandicap</td>
                <td></td>
            </tr>
        }
        </table>
        <br /><br />
    }
}